package com.study.行为型模式.迭代器模式;

import java.util.ArrayList;
import java.util.Iterator;

public class InfoCollegeIterator implements Iterator {

    ArrayList<Department> departments;
    int index = -1; //索引

    public InfoCollegeIterator(ArrayList<Department> departments) {
        this.departments = departments;
    }

    @Override
    public boolean hasNext() {
        if (index >= departments.size() - 1) {
            return false;
        } else {
            index += 1;
            return true;
        }
    }

    @Override
    public Object next() {
        return departments.get(index);
    }

    @Override
    public void remove() {

    }
}
